-
Notifications
You must be signed in to change notification settings - Fork 306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Kernelspec Caching #1271
base: main
Are you sure you want to change the base?
Kernelspec Caching #1271
Conversation
Hi @blink1073. The kernelspec cache test failures are due to a missing EDIT: Hmm, I'm also seeing a different issue not seen in dev (sorry about that), so will need to address that as well, but I think my questions are still applicable (although it looks like Windows must include |
|
Thanks Steve. Yeah, that's the issue I saw as well and things are moving along better in my fork. I had originally thought it was the watchdog dependency but, after closer inspection, it was all about the indexing issue. Looks like the docs build is failing due to the new sub folder for the monitors that I'll follow up on. Thanks for your help.
|
Kernelspec Caching
This pull request introduces a new configurable feature called KernelSpec Caching. The
KernelSpecCache
instance supports the same retrieval methods as aKernelSpecManager
and contains the configuredKernelSpecManager
instance. If caching is not enabled (by default), the cache is a direct pass-through to theKernelSpecManager
, otherwise it acts as a read through cache, deferring to theKernelSpecManager
on any cache misses. This functionality has proven useful in Enterprise Gateway where it has existed for a few years. In that implementation, thewatchdog
package is used to determine cache updates.By introducing kernelspec caching, we can now define events corresponding to the addition, update, and deletion of kernel specifications and get closer to removing the 10-second polling performed by Lab once it has been updated to consume kernelspec events.
Monitors
Besides its enablement via the
cache_enabled
configurable,KernelSpecCache
supports pluggable monitors that are responsible for detecting changes to the cached items and keeping the cache updated due to out-of-band updates. A kernelspec cache monitor is registered via the entry points group"jupyter_server.kernelspec_monitors"
to introduce a layer of decoupling. This pull request includes two monitors:KernelSpecWatchdogMonitor
under the entry point name"watchdog-monitor"
:This monitor uses the
watchdog
package to monitor changes to directories containing kernelspec definitions. Because this monitor uses thewatchdog
package, an optional dependency has been added for users wishing to use this monitor:pip install jupyter_server[watchdog-monitor]
KernelSpecPollingMonitor
under the entry point name"polling-monitor"
:This monitor periodically polls (via a configurable
interval
trait) for kernelspec changes and computes an MD5 hash on each entry to further determine changes. It only updates the cache when the hash values have changed (or are new) and when it determines a kernelspec has been removed. The interval's default value is 30 (sec).KernelSpecPollingMonitor
is the default monitor used since it does not introduce new packages.Other monitors that would be useful are:
"watchdog-monitor"
, but usingwatchfiles
instead, since we have other needs forwatchfiles
. At that point, we may be able to make"watchfiles-monitor"
the default - assuming we include thewatchfiles
package.KernelSpec caching is disabled by default. If we want to enable it by default, we'll need to adjust some tests (probably only kernelspecs and perhaps kernels api tests) to configure a much shorter polling interval, or switch the default to the
"watchfiles-monitor"
(once implemented) since it sounds like there's a preference towatchfiles
overwatchdog
. (Note: Enterprise Gateway happened to usewatchdog
a few years ago, thus the reason the watchdog monitor exists. If we built a"watchfiles-monitor"
, I have no affinity for"watchdog-monitor"
and see no reason to keep it unless we find advantages overwatchfiles
.)Class Hierarchy
KernelSpecCache
contains instances of theKernelSpecManager
andKernelSpecMonitorBase
that corresponds to themonitor_name
configurable.Event Support (Future)
With caching in place, we should be able to fire add and update kernelspec events from
KernelSpecCache.put_item()
and delete kernelspec events fromKernelSpecCache.remove_item()
since their corresponding all items methods simply call on the singleton versions.